package com.nova.bluetooth;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.view.View;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;
import androidx.fragment.app.Fragment;

import com.nova.bluetooth.adapter.MainViewPagerAdapter;
import com.nova.bluetooth.base.BaseActivity;
import com.nova.bluetooth.databinding.ActivityAppMainBinding;
import com.nova.bluetooth.databinding.ActivityLoginBinding;
import com.nova.bluetooth.helpUtils.OnClickEvent;
import com.nova.bluetooth.ui.ai.AITabFragment;
import com.nova.bluetooth.ui.device.DeviceTabFragment;
import com.nova.bluetooth.ui.mine.MineTabFragment;

import java.util.ArrayList;
import java.util.List;

/**
 * APP 主界面
 */
public class AppMainActivity extends BaseActivity {
    private ActivityAppMainBinding binding;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        binding = ActivityAppMainBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());
        setPaddingBottom(this,binding.getRoot());

        initView();
    }
    private void initView() {
        binding.includeTab.llTabDevice.setSelected(true);
        binding.includeTab.llTabDevice.setOnClickListener(onClickListener);
        binding.includeTab.llTabAi.setOnClickListener(onClickListener);
        binding.includeTab.llTabMine.setOnClickListener(onClickListener);

        List<Fragment> fragmentList = new ArrayList<>();
        fragmentList.add(new DeviceTabFragment());
        fragmentList.add(new AITabFragment());
        fragmentList.add(new MineTabFragment());
        MainViewPagerAdapter mainViewPagerAdapter = new MainViewPagerAdapter(getSupportFragmentManager(), fragmentList);
        binding.viewpager.setAdapter(mainViewPagerAdapter);
    }

    private void setTabSelect(View view){
        binding.includeTab.llTabDevice.setSelected(false);
        binding.includeTab.llTabAi.setSelected(false);
        binding.includeTab.llTabMine.setSelected(false);
        view.setSelected(true);

        if (view.getId() == R.id.ll_tab_device){
            binding.viewpager.setCurrentItem(0,false);
        }else if (view.getId() == R.id.ll_tab_ai){
            binding.viewpager.setCurrentItem(1,false);
        }else if (view.getId() == R.id.ll_tab_mine){
            binding.viewpager.setCurrentItem(2,false);
        }
    }

    private final OnClickEvent onClickListener = new OnClickEvent() {

        @Override
        public void singleClick(View v) {
            if (v.getId() == R.id.ll_tab_device ||
                    v.getId() == R.id.ll_tab_ai ||
                    v.getId() == R.id.ll_tab_mine){
                setTabSelect(v);
            }
        }
    };
}